﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;

namespace LIK.NetAssemblyChecker
{
    internal abstract class Commons
    {
        public static List<string> NetSystemAssemblyNames = new List<string> {
            "mscorlib", 
            "System", 
            "System.Xml", 
            "Microsoft.VisualBasic",
            "System.Configuration",
            "System.Data", 
            "System.Deployment",
            "System.Design", 
            "System.DirectoryServices",
            "System.Drawing",
            "System.Web", 
            "System.Windows.Forms" };

        internal enum FileObjectIcon : int
        {
            Folder = 0,
            ExeFile = 1,
            DllFile = 2,
            Ref = 3
        }

        internal static string FolderToCheck = "";

        internal static List<string> RunTimeVersions = new List<string>();
        internal static List<string> AssemblyDependants = new List<string>();

        internal static void CheckRunTime(string ImageRuntimeVersion)
        {
            if (!RunTimeVersions.Contains(ImageRuntimeVersion))
            {
                RunTimeVersions.Add(ImageRuntimeVersion);
            }
        }

        internal static void CheckAssemblyDependants(string nodename)
        {
            if (!AssemblyDependants.Contains(nodename))
                AssemblyDependants.Add(nodename);
        }


        internal static Assembly TryToLoadAssemblyFromFile(string path)
        {
            Assembly assembly = null;
            try
            {
                if (File.Exists(path))
                {
                    assembly = Assembly.LoadFile(path);
                }
            }
            catch
            {
                assembly = null;
            }
            return assembly;
        }
        internal static Assembly TryToLoadAssemblyFromName(string assemblyName)
        {
            Assembly assembly = null;
            if (assembly == null)
            {
                try
                {
                    assembly = Assembly.LoadWithPartialName(assemblyName);
                }
                catch
                {
                    assembly = null;
                }
            }
            return assembly;
        }


    }
}
